﻿using System;
using Microsoft.Practices.Unity;
using WinClient.Service.Interfaces;
using System.Reflection;


namespace WinClient.Core
{
    public class ServiceProxy : IServiceProxy
    {
        private UnityContainer mUnityContainer = new UnityContainer();

        public ServiceProxy()
        {
            GetUpdate("asasas");

            Assembly assembly = Assembly.LoadFrom(@"WinClient.Service.Interfaces.dll");
            Type interfaceType = assembly.GetType("WinClient.Service.Interfaces.Module1.ICustomerService");

            Assembly serviceAssembly = Assembly.LoadFrom(@"Foo\WinClient.Service.Implementations.dll");
            Type serviceType = serviceAssembly.GetType("WinClient.Service.Implementations.Module1.CustomerService");
            
            // Singleton
            mUnityContainer.RegisterType(interfaceType, serviceType, new ContainerControlledLifetimeManager());

            
        }

        public IService RetriveServiceImplementation<T>()
        {

            return (IService)mUnityContainer.Resolve<T>();
        }

        public T GetService<T>()
        {
            return (T)mUnityContainer.Resolve(typeof(T));
        }


        public void GetUpdate(string pGuid)
        {
            Foo foo = new Foo();
            foo.StartUpdate();
        }

    }
}
